const mongoose = require('./db');
const { Schema } = mongoose;

// 用户（user）表
const userSchema = new Schema({
    name: { type: String, required: true },
    password: { type: String, required: true },
    sex: { type: String },
    age: { type: Number },
    phone: { type: Number },
    face_id: { type: String },
    record: { type: Array },
    doctor_id: [{ type: Schema.Types.ObjectId, ref: 'Doctor' }]
});
const User = mongoose.model('User', userSchema);

// 医生（Doctor）表
const doctorSchema = new Schema({
    name: { type: String, required: true },
    password: { type: String, required: true },
    department: { type: String },
    status: { type: Boolean,default: true },
    qualification: { type: Boolean,default:false },
    user_id: [{ type: Schema.Types.ObjectId, ref: 'User' }]
});
const Doctor = mongoose.model('Doctor', doctorSchema);

// 后台（backstage）表
const backstageSchema = new Schema({
    name: { type: String, required: true },
    password: { type: String, required: true },
    position: { type: String },
    authority: { type: Array },
});
const Backstage = mongoose.model('Backstage', backstageSchema);

// 动态（Dynamic）表
const dynamicSchema = new Schema({
    tabs: { type: String },
    address: { type: String },
    txt: { type: String },
    times: { type: Date },
    path: { type: String },
    likes: { type: Array },
    userid: { type: Schema.Types.ObjectId, ref: 'User' }
});
const Dynamic = mongoose.model('Dynamic', dynamicSchema);

// 评论（reviews）表
const reviewsSchema = new Schema({
    txt: { type: String },
    times: { type: Date },
    path: { type: String },
    dynamicid: { type: Schema.Types.ObjectId, ref: 'Dynamic' }
});
const Reviews = mongoose.model('Reviews', reviewsSchema);

// 药品表（drug）
const drugSchema = new Schema({
    name: { type: String, required: true },// 药品名称
    specification: { type: String },//药品规格
    reference: { type: String },//批准文号
    firm: { type: String },//生产厂商
    major: { type: String },//主治功能
    price: { type: Number },//起步价格
    image: { type: String },//药品图片
    tag: { type: String },//药品标签 处方药等
});
const Drug = mongoose.model('Drug', drugSchema);

// 店铺表（shop）
const shopSchema = new Schema({
    name: { type: String, required: true },
    address: { type: String },
    platform: { type: String },
    druggid: { type: Schema.Types.ObjectId, ref: 'Drug' },
    image: { type: String }
});
const Shop = mongoose.model('Shop', shopSchema);

// 店铺药品规格表（shopdrug）
const shopdrugSchema = new Schema({
    shopid: { type: Schema.Types.ObjectId, ref: 'Shop' },
    datetime: { type: Date },
    price: { type: Number },
    num: { type: Number },
    image: { type: String }
});
const ShopDrug = mongoose.model('ShopDrug', shopdrugSchema);

module.exports = {
    User,
    Doctor,
    Backstage,
    Dynamic,
    Reviews,
    Drug,
    Shop,
    ShopDrug
};